package gui;

import ij.ImagePlus;
import ij.gui.ImageCanvas;
import ij.process.ImageProcessor;
import javax.swing.JPanel;

/**
 *
 * @author Ragnar
 */
public class ProcessedImagePanel extends JPanel implements Runnable
{
    private ImageCanvas ic;
    private ImagePlus image;
    private ImagePanel ip;

    public ProcessedImagePanel(ImagePanel ip)
    {
        this.image = new ImagePlus();
        this.ic = new ImageCanvas(image);
        this.add(ic);
        this.ip = ip;
        Thread t = new Thread(this);
        t.start();
        this.repaint();
    }
    
//    @Override
//    public void paintComponent(Graphics g)
//    {
//        //super.paintComponent(g);
//        
//        //((Graphics)g).drawImage(this.image.getImage(), 0, 0, this);
//    }
    
    @Override
    public void run()
    {
        while (true)
        {
            if (ip.getIMP() != null)
            {
                this.image = ip.getIMP();
                ImageProcessor impro = this.image.getProcessor();
                impro.setValue(200);
                this.image.updateAndDraw();
            }
            try
            {
                Thread.sleep(50);
                this.repaint();
            }
            catch (InterruptedException ex) {}
        }
    }    
}
